import React from 'react'
import { getHotkey } from '../../../api'
class Hotkey extends React.Component {
    constructor() {
        super()
        this.state = {
            data: [],
        }
    }
    //dom挂载前
    componentWillMount() {
        getHotkey().then((res) => {
            this.setState({
                data: res.data.result.hots
            })
        })
    }
    //点击热搜关键字添加到搜索框
    handleInputAdd = (e) => {
        //父组件传过来的方法
        this.props.callback(e)
    }
    render() {
        let { data } = this.state
        let lis = data.map(({first, second }) => {
            //重新给热搜Id
            let g  = Math.random()*9
            return (
                <span className="tag" onClick={this.handleInputAdd.bind(this, first)} key={second+g}>{first}</span>
            )
        })
        return (
            lis
        )
    }
}

export default Hotkey